﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>创伤中心信息系统</title>
    <link rel="stylesheet" href="~/Scripts/ligerUI/skins/Aqua/css/ligerui-all.css" />
    <link rel="stylesheet" href="~/Scripts/ligerUI/skins/ligerui-icons.css" />
    <link rel="stylesheet" href="~/Scripts/ligerUI/skins/Gray2014/css/all.css" />
    <link rel="stylesheet" href="~/Content/css/main.css" />
    <link rel="stylesheet" href="~/Content/css/menu.css" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js"></script>    
</head>
<body>
    <div id="header">
        <div class="logoContent">
            <img id="logo" src="~/Content/images/logo.jpg" style="margin-top:-10px;" />
            <span id="company" style="margin-left:10px;">创伤中心信息系统</span>
        </div>
        <div class="navright">
            <div id="userinfo" class="item">
                <div style="position: relative; float: left;">
                    <div id="Username" style="font-size: 14px; padding-right: 5px; width: 60px; text-align: right; float: left; height: 50px; line-height: 50px;"></div>
                </div>
                <div id="portrait">
                    <img id="userheader" width="40" style="border-radius: 100%; margin-top: -12px;" />
                </div>
            </div>
        </div>
    </div>
    <div id="layout" style="width: 100%; margin-top: 4px;">
        <div position="left" title="功能菜单" id="accordion1">
        </div>
        <div position="center" id="framecenter">
            <div tabid="home" title="桌面" style="height: 300px">
                <iframe frameborder="0" name="home" id="home"></iframe>
            </div>
        </div>
        <div position="bottom">
            <div style="text-align:center;font-size:12px;"></div>
        </div>
    </div>
    <script type="text/javascript">
        var tab;
        var accordion;
        function onResize() {
            var winH = $(window).height(), winW = $(window).width();
            $("#pageloading").height(winH);
            initLayout();
        }

        $(function () {
            //布局
            $("#layout").ligerLayout({ leftWidth: 170, bottomHeight: 25, space: 4, allowBottomResize: false, allowLeftResize: false, allowRightResize: false, height: '100%', onHeightChanged: f_heightChanged, isRightCollapse: true });

            var height = $(".l-layout-center").height();

            //Tab
            tab = $("#framecenter").ligerTab({
                height: height,
                dblClickToClose: true,
                showSwitch: true,     //显示切换窗口按钮
                showSwitchInTab: true //切换窗口按钮显示在最后一项 ,
            });

            //用户信息
            f_user();
            getUserInfo();
            $("#userinfo").click(function (e) { f_dropdown(e) });
            onResize();
            $(window).resize(function () {
                onResize();
            });

            //菜单
            accordion = $("#accordion1").ligerAccordion({ height: height - 32 });
            menu();

        });

        //鼠标悬停在用户头像的样式
        function f_user() {
            $("#userinfo").hover(
                function () {
                    $(this).addClass("userover");
                },
                function () {
                    $(this).removeClass("userover");
                }
            )

        }

        //初始化菜单
        function menu() {
            var mainmenu = $("#accordion1");

            $.getJSON("/Home/InitMenu", function (data, textStatus) {
                $(data).each(function (i, app) {
                    var appmenu = $("<div title='" + app.Name + "' id='menuId" + app.Id + "'><ul class='sidebar-menu'></ul></div>");

                    $(app.children).each(function (gi, group) //包括分组的部分
                    {
                        if (group.children) {
                            var groupmenu = $("<li class='sub-menu'><a ><img /> " + group.Name + "<span class='arrow'></span></a><ul class='sub'></ul><li>");
                            var groupli = $("<li><a ><img /> " + group.Name + "</a><ul></ul><li>");

                            groupmenu.find("img").attr("src", "../Content/" + group.ImgUrl);
                            groupli.find("img").attr("src", "../Content/" + group.ImgUrl);

                            $(group.children).each(function (i, submenu) {
                                var subitem = $('<li><a class="menulink" ><img /> ' + submenu.Name + '</a></li>');
                                subitem.find("img").attr("src", "../Content/" + submenu.ImgUrl);
                                subitem.find("a").attr({
                                    tabid: submenu.Id,
                                    tabtext: submenu.Name,
                                    taburl: group.Path == "" ? "" : (submenu.Path)
                                });
                                $("ul:first", groupmenu).append(subitem);
                            });
                            $("ul:first", appmenu).append(groupmenu);
                        }
                        else {
                            var subitem = $('<li><a class="menulink"><img /> ' + group.Name + '</a></li>');
                            subitem.find("img").attr("src", "../Content/" + group.ImgUrl);
                            subitem.find("a").attr({
                                tabid: group.Id,
                                tabtext: group.Name,
                                taburl: group.Path == "" ? "" : (group.Path)
                            });

                            $("ul:first", appmenu).append(subitem);
                        }
                    });
                    $(mainmenu).append(appmenu);
                })

                accordion._render();
                onResize();

                $(data).each(function (i, app) {
                    if (app.ParentId == 0) {
                        var accordion = $("#menuId" + app.Id).prev();
                        if (app.children.length == 0) {
                            $("#menuId" + app.Id).remove();
                            accordion.find(".l-accordion-toggle").remove();
                        }
                        var menulink = $('<a class="menulink" style="display:block;line-height:40px;width:160px;"><img style="margin-top:-5px;"/> ' + app.Name + '</a>');
                        menulink.find("img").attr("src", "../Content/" + app.ImgUrl);
                        menulink.attr({
                            tabid: app.Id,
                            tabtext: app.Name,
                            taburl: app.Path == "" ? "" : (app.Path)
                        });
                        var inner = accordion.find(".l-accordion-header-inner");
                        inner.html("");
                        inner.append(menulink);
                    }

                });

                $('.sub-menu > a').click(function () {
                    var last = $('.sub-menu.open');
                    last.removeClass("open");
                    $('.sub').slideUp(200);

                    var sub = jQuery(this).next();
                    if (sub.is(":visible")) {
                        $(this).parent().removeClass("open");
                        sub.slideUp(200);
                    } else {
                        $(this).parent().addClass("open");
                        sub.slideDown(200);
                    }
                });

                mainmenu.find("a.menulink").click(function () {
                    var tabid = $(this).attr('tabid'),
                       url = $(this).attr("taburl"),
                       text = $(this).attr('tabtext');

                    if (!url) return;

                    f_addTab(tabid, text, url);
                });

                $("#home").attr("src", "/Home/Desktop");
            })
        }

        //点击登录用户下列菜单
        function f_dropdown(e) {
            var sysitem = [];
            var windowsswitch;
            if ($(".l-userinfo-panel").length == 0) {
                windowsswitch = $("<div class='l-userinfo-panel'><ul class='userinfolist'></ul></div>").appendTo($("#userinfo"));
                sysitem.push({ icon: '../Content/images/icon/1.png', title: "退出系统", click: function () { logout(); } });

                $(sysitem).each(function (i, item) {
                    var subitem = $('<li><img/><span></span></li>');
                    $("img", subitem).attr("src", item.icon);
                    $("span", subitem).html(item.title);
                    $("ul:first", windowsswitch).append(subitem);
                    subitem.click(function () { item.click(item); });
                })
            }
            else
                windowsswitch = $(".l-userinfo-panel");

            $("li", windowsswitch).live('click', function () {
                $(".l-userinfo-panel").hide();
            }).live('mouseover', function () {
                var jitem = $(this);
                jitem.addClass("over");
            }).live('mouseout', function () {
                var jitem = $(this);
                jitem.removeClass("over");
            });
            windowsswitch.css({
                top: $("#userinfo").offset().top + $("#userinfo").height() + 10,
                width: $("#userinfo").width()
            });

            if ($(".l-userinfo-panel").css('display') == 'none')
                $(".l-userinfo-panel").show();
            else
                $(".l-userinfo-panel").hide();

            $(document).one("click", function () {
                $(".l-userinfo-panel").hide();
            });

            e.stopPropagation();
        }

        //获取登录用户信息
        function getUserInfo() {
            $.getJSON("/Home/GetLoginUser", function (data, textStatus) {
                $("#Username").html("<div style='cursor:pointer'>" + data.Name + "</div>");
                if (false)
                    $("#userheader").attr("src", ""); //自定义头像
                else
                    $("#userheader").attr("src", "../Content/images/noheadimage.jpg");
            });
        }

        //退出系统
        function logout() {
            $.ligerDialog.confirm('您确认要退出系统？', function (yes) {
                if (yes) {
                    $.ajax({
                        type: 'post',
                        url: '/Login/LoginOut',
                        success: function (result) {
                            javascript: location.replace("/Login/Index");
                        }
                    });
                }
            });
        }

        function initLayout() {
            var h = document.documentElement.clientHeight;
            var w = document.documentElement.clientWidth;

            $(".l-window-mask").height(h);
            $(".l-window-mask").width(w);

            var dialogwidth = $(".l-dialog").width();
            var dialogheight = $(".l-dialog").height();

            var offsettop = (h * 0.5 - dialogheight * 0.5) > 0 ? (h * 0.5 - dialogheight * 0.5) : 0;
            var offsetleft = (w * 0.5 - dialogwidth * 0.5) > 5 ? (w * 0.5 - dialogwidth * 0.5) : 5;
            $(".l-dialog").css({ 'top': offsettop, 'left': offsetleft });
        }

        function f_addTab(tabid, text, url) {
            top.tab.addTabItem({ tabid: tabid, text: text, url: url });
        }

        function f_heightChanged(options) {
            if (tab)
                tab.addHeight(options.diff);
            if (accordion && options.middleHeight - 32 > 0)
                accordion.setHeight(options.middleHeight - 32);

        }
        $(document).ready(function () {
            if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0") {
                $.ligerDialog.error("本系统不支持IE6浏览器");
            }
            if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE7.0") {
                $.ligerDialog.error("本系统不支持IE7浏览器");
            }
        })
    </script>
</body>
</html>